package org.stratusdb.store;

import org.stratusdb.error.EnumError;
import org.stratusdb.error.Error;
import org.stratusdb.metadata.Connection;
import org.stratusdb.store.postgres.PostgresStore;


public enum EnumStore {
	POSTGRES,
	MYSQL,
	STRATUS;
	
	private static final EnumStore[] values  = { POSTGRES, MYSQL, STRATUS };
	
	public static EnumStore get(int i){
		return values[i];
	}
	
	public static EnumStore get(String type){
		if(type.equalsIgnoreCase("POSTGRES"))
			return POSTGRES;
		else if(type.equalsIgnoreCase("MYSQL"))
			return MYSQL;
		else if(type.equalsIgnoreCase("STRATUS"))
			return STRATUS;
		return null;
	}
	/**
	 * 
	 * switch enum and return concrete object
	 * 
	 */
	public static AbstractStore getStoreObject(Connection con) {
		AbstractStore as = null;
		switch (con.getStore()) {
		case POSTGRES: as = new PostgresStore();
		break;
		case MYSQL: as = null;
		break;
		default:
			return null;
		}
		return as;
	}
	
	public static synchronized Error createStoreNotExistsErr(
			String type) {
		String args[] = { type };
		Error error = new Error(EnumError.STORE_NOT_EXISTS, args);
		return error;
	}
}
